<?php

namespace App\Models;

use Illuminate\Support\Collection;

class CarFavourite extends Model
{
    protected $table = 'yf_car_favourite';
    protected $primaryKey = 'my_car_id';
    public $timestamps = false;
    protected $guarded = ['my_car_id'];

    public static function getFavouriteCars(int $userId) : Collection
    {
        return self::from('yf_car_favourite as car_favourite')
            ->join('yf_car_type as car_type', 'car_type.car_type_id', '=', 'car_favourite.car_type_id')
            ->join('yf_car_audi as car_audi', 'car_audi.car_audi_id', '=', 'car_type.car_audi_id')
            ->where('car_favourite.user_id', $userId)
            ->latest('car_is_default')
            ->get();
    }
}
